<!DOCTYPE html>
<html>
<head>
	<title>Big store</title>
	<!-- for-mobile-apps -->
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta property="og:title" content="Vide" />
	<meta name="keywords" content="Big store" />
	<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
	function hideURLbar(){ window.scrollTo(0,1); } </script>
	<!-- //for-mobile-apps -->
	<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
	<!-- Custom Theme files -->
	<link href="css/style.css" rel='stylesheet' type='text/css' />
	<!-- js -->
	   <script src="js/jquery-1.11.1.min.js"></script>
	<!-- //js -->
	<!-- start-smoth-scrolling -->
	<script type="text/javascript" src="js/move-top.js"></script>
	<script type="text/javascript" src="js/easing.js"></script>
	<script type="text/javascript">
		jQuery(document).ready(function($) {
			$(".scroll").click(function(event){
				event.preventDefault();
				$('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
			});
		});
	</script>
	<!-- start-smoth-scrolling -->
	<link href="css/font-awesome.css" rel="stylesheet"/>
</head>
<body>
<div class="header">
	<div class="container">
		<div class="logo">
			<h1 ><a href="index.html"><b>T<br/>H<br/>E</b>Big Store<span>The Best Supermarket</span></a></h1>
		</div>
		<div class="head-t">
			<ul class="card">
				<li id="usercenter" style="display: none"><a class="withtoken" id="a_usercenter" href="usercenter.html" ><i class="fa fa-user" aria-hidden="true"></i>个人中心</a></li>
				<li id="login"><a class="withtoken" href="login.html" ><i class="fa fa-user" aria-hidden="true"></i>登录</a></li>
				<li id="register"><a class="withtoken" href="register.html" ><i class="fa fa-arrow-right" aria-hidden="true"></i>注册</a></li>
				<li><a class="withtoken" href="orderlist.html" ><i class="fa fa-file-text-o" aria-hidden="true"></i>订单列表</a></li>
				<li><a class="withtoken" href="wishlist.html" ><i class="fa fa-heart" aria-hidden="true"></i>收藏</a></li>
				<li><a class="withtoken" href="cart.html" ><i class="fa fa-shopping-cart" aria-hidden="true"></i>购物车</a></li>
			</ul>
		</div>
		<script type="text/javascript">
            $(function(){
                var _this1=null;
                $('.nav>li').hover(function(){
                    _this1=$(this);
                    _this1.find('.second-nav').show();
                    var _this2=null;
                    _this1.find('.second-nav').find('li').hover(function(){
                        _this2=$(this);
                        _this2.find('.third-nav').show();
                        _this2.find('.third-nav').hover(function(){
                            $(this).show();
                        },function(){
                            $(this).hide();
                        });
                    },function(){
                        _this2.find('.third-nav').hide();
                    });
                },function(){
                    _this1.find('.second-nav').hide();
                });
            });
		</script>
		<div class="nav-top">
			<nav class="navbar navbar-default">

				<div class="collapse navbar-collapse" id="bs-megadropdown-tabs">
					<ul class="nav navbar-nav ">
						<li> <!--class=" active"--> <a href="index.html" class="hyper "><span>主页</span></a></li>

						<li class="dropdown">
							<a href="#" class="dropdown-toggle  hyper" data-toggle="dropdown" >
								<span> 商品类别 <b class="caret"></b></span>
							</a>
							<ul class="dropdown-menu multi second-nav" id="dropdown-ul">
								<!--<li ><a href="#">饮料&nbsp;&nbsp;&nbsp;&nbsp;></a>
									<ul class="dropdown-menu multi third-nav">
										<li><a href="#">汽水饮料</a></li>
										<li><a href="#">酒精饮料</a></li>
										<li><a href="#">纯牛奶</a></li>
										<li><a href="#">酸牛奶</a></li>
										<li><a href="#">其他饮料</a></li>
									</ul>
								</li>
								<li><a href="#">零食&nbsp;&nbsp;&nbsp;&nbsp;></a>
									<ul class="dropdown-menu multi third-nav">
										<li><a href="#">辣条</a></li>
										<li><a href="#">饼干</a></li>
										<li><a href="#">面包</a></li>
										<li><a href="#">坚果</a></li>
										<li><a href="#">其他零食</a></li>
									</ul>
								</li>
								<li><a href="#">水果&nbsp;&nbsp;&nbsp;&nbsp;></a>
									<ul class="dropdown-menu multi third-nav">
										<li><a href="#">苹果</a></li>
										<li><a href="#">香蕉</a></li>
										<li><a href="#">葡萄</a></li>
										<li><a href="#">芒果</a></li>
										<li><a href="#">其他水果</a></li>
									</ul>
								</li>
								<li><a href="#">烟酒&nbsp;&nbsp;&nbsp;&nbsp;></a></li>
								<li><a href="#">厨具&nbsp;&nbsp;&nbsp;&nbsp;></a></li>
								<li><a href="#">蔬菜&nbsp;&nbsp;&nbsp;&nbsp;></a></li>
								<li><a href="#">鲜肉&nbsp;&nbsp;&nbsp;&nbsp;></a></li>-->
							</ul>
						</li>

						<li><a href="hot.html" class="hyper "><span> 热卖商品 </span></a></li>

						<li><a href="activities.html" class="hyper "><span> 促销活动 </span></a></li>

						<li><a href="contact.html" class="hyper"><span> 联系我们 </span></a></li>
					</ul>
				</div>
			</nav>

			<!--<div class="cart" >
                <span class="fa fa-shopping-cart my-cart-icon"><span class="badge badge-notify my-cart-badge"></span></span>
            </div>-->
			<div class="clearfix"></div>
		</div>

	</div>
</div>
  <!---->

   <!--banner-->
<div class="banner-top">
	<div class="container">
		<h3 >购物车</h3>
		<h4><a href="index.html">Home</a><label>/</label>shoppingcart</h4>
		<div class="clearfix"> </div>
	</div>
</div>

	<!-- contact -->
		<div class="check-out">	 
			<div class="container">
				<div class="spec ">
					<h3>购物车</h3>
						<div class="ser-t">
							<b></b>
							<span><i></i></span>
							<b class="line"></b>
						</div>
				</div>
					<script>$(document).ready(function(c) {
						$('.close1').on('click', function(c){
							$('.cross').fadeOut('slow', function(c){
								$('.cross').remove();
							});
							});
						});
				   </script>

				 <table class="table cartTable" >
					 <tbody id="cartTable">
						 <tr>
							 <th class="t-head head-it "><input type="checkbox" onclick="checkall(this)" name="selectall"> 全选</input></th>
							 <th class="t-head head-it ">商品</th>
							 <th class="t-head">价格</th>
							 <th class="t-head">数量</th>
							 <th class="t-head">操作</th>
						 </tr>
						 <!--<tr class="cross">
							 <td class="t-data">
								 <input type="checkbox" class="selectone" name="selectone" onclick="getTotalPrice()"/>
							 </td>
							 <td class="t-data ring-in">
								 <a href="other/single.html" class="at-in">
									 <img src="images/wi1.png" class="img-responsive" alt=""/>
								 </a>
								 <div class="sed">
									 <h5>Sed ut perspiciatis unde</h5>
								 </div>
							 </td>
							 <td class="t-data money">￥20.00</td>
							 <td class="t-data">
								 <div class="quantity">
									 <div class="quantity-select">
										 <div class="entry value-minus">&nbsp;</div>
										 <div class="entry value"><span class="span-1">1</span></div>
										 <div class="entry value-plus active">&nbsp;</div>
									 </div>
								 </div>
							 </td>

							 <td class="t-data t-w3l"><a class=" add-1" onclick="deleteFromCart(0)">DELETE</a></td>
						 </tr>-->
					 </tbody>

				 </table>
				<div>
					<a onclick="goumai()" style="float: right;margin-left: 30px" class="btn btn-warning" value="  立即购买  ">立即购买</a>
					<h3 style="float: right;line-height:40px">总价：￥<span id="totalPrice">0</span></h3>
				</div>
			</div>
		</div>
		 				
	<!--quantity-->
			<script>
				function checkall(e) {
				    //alert(''+e);
					if(e.checked == true){
					    var checkboxs = document.getElementsByName('selectone');
					    //alert('checkboxs.length:'+checkboxs.length);
					    for(i=0;i<checkboxs.length;i++){
                            checkboxs[i].checked = true;
						}
                        getTotalPrice();
					}else {
                        var checkboxs = document.getElementsByName('selectone');
                        //alert('checkboxs.length:'+checkboxs.length);
                        for(i=0;i<checkboxs.length;i++){
                            checkboxs[i].checked = false;
                        }
                        getTotalPrice();
					}
                }
                function getTotalPrice() {
                    var totalprice = document.getElementById('totalPrice');
                    //alert('total:'+totalprice.html());
                    var row = document.getElementsByClassName('selectone');
                    //alert('row:'+row.length);
                    var n = 0.0;
                    for(var i=0;i < row.length; i ++){
                        //alert(row[i].checked);
                        if(row[i].checked == true){

//                            var priceStr = row[i].parent().parent().find('.money').innerHTML.replace('￥','');
                            var childNodes = row[i].parentNode.parentNode.childNodes;
                            console.log('childNodes',childNodes);
                            console.log('childNodes5',childNodes[2]);
                            var money = childNodes[2].innerText.replace('￥','');
                            console.log('money',money);
                            n += parseInt(money);
                        }
                    }
                    totalprice.innerHTML = ""+n;
                }
				function plus(e) {
                    var price = parseInt(e.getAttribute('price'));
                    console.log('price',price);
					var divchils = e.parentNode.childNodes;
					var divUpd = divchils[1].firstChild;
					console.log('value',divUpd);
					var parent = e.parentNode.parentNode.parentNode.parentNode;
					var money = parent.childNodes[2];
                    console.log('money',money);
					//var price = parseInt( money.innerHTML.replace('￥','') );

                    var newVal = parseInt(divUpd.innerHTML, 10)+1;
                    divUpd.innerHTML = newVal;
                    money.innerHTML = '￥'+ (price*newVal);

                    getTotalPrice();
                }
                function minus(e) {
                    var price = parseInt(e.getAttribute('price'));
                    console.log('price',price);
                    var divchils = e.parentNode.childNodes;
                    var divUpd = divchils[1].firstChild;
                    var newVal = parseInt(divUpd.innerHTML, 10)-1;
                    console.log('value',divUpd);
                    var parent = e.parentNode.parentNode.parentNode.parentNode;
                    var money = parent.childNodes[2];
                    console.log('money',money);
					
                    if(newVal>=1){
                        divUpd.innerHTML = newVal;
                        money.innerHTML = '￥'+(price*newVal);
					}
                    getTotalPrice();
                }

                //从浏览器URL获取GET请求参数
                function getQueryString(name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                    var r = window.location.search.substr(1).match(reg);
                    if (r != null) return unescape(r[2]); return null;
                }
                var token = getQueryString('t')==null? '':getQueryString('t');
                //var uid = getQueryString('uid')==null? '':getQueryString('uid');
				//uid = 4;//----------------------------------------------
				//token = 'c4ca4238a0b923820dcc509a6f75849b';//---------------------------

                function deleteFromCart(id) {
                    if(confirm('确定删除吗？')){
                        var responseBody = $.ajax({
                            url:"/v1/cart/"+id,
                            method:"DELETE",
                            async:false,
                        });
                        if(responseBody.status==200 || responseBody.status==203 ){
                            window.location='cart.html?t='+token;
                        }
                    }

                }
                function loadCart() {
                    var responseBody = $.ajax({
                        url:"/v1/cart",
                        method:"GET",
                        async:false,
                        headers:{
                            t:token/*,
							u:uid*/
                        }
                    });
                    if(responseBody.status == 444){
                        alert('session bad');
                        window.location='login.html';
                    }else if(responseBody.status==200){
                        var cartTable = document.getElementById('cartTable');
                        var cartData = responseBody.responseJSON;
                        for(i=0;i<cartData.length;i++){
                            var responseBody = $.ajax({
                                url:"/v1/products/"+cartData[i].pid,
                                method:"GET",
                                async:false,
                                /*headers:{t:token}*/
                            });
                            var product = responseBody.responseJSON;

                            /*
							 <td class="t-data">
							 	<input type="checkbox" class="selectone" name="selectone" onclick="getTotalPrice()"/>
							 </td>
							 <td class="t-data ring-in">
							 	<a href="other/single.html" class="at-in">
							 		<img src="images/wi1.png" class="img-responsive" alt=""/>
							 	</a>
								 <div class="sed">
								 	<h5>Sed ut perspiciatis unde</h5>
								 </div>
							 </td>
							 <td class="t-data money">￥20.00</td>
							 <td class="t-data">
								 <div class="quantity">
									 <div class="quantity-select">
										 <div class="entry value-minus">&nbsp;</div>
										 <div class="entry value"><span class="span-1">1</span></div>
										 <div class="entry value-plus active">&nbsp;</div>
							 	 	 </div>
							 	 </div>
							 </td>

							 <td class="t-data t-w3l"><a class=" add-1" onclick="deleteFromCart(0)">DELETE</a></td>
                             */
                            var tr = document.createElement('tr');
                            tr.setAttribute('class','cross');

                            var td1 = document.createElement('td');
                            td1.setAttribute('class','t-data');
                            var input1 = document.createElement('input');
                            input1.setAttribute('type','checkbox');
                            input1.setAttribute('class','selectone');
                            input1.setAttribute('name','selectone');
                            input1.setAttribute('onclick','getTotalPrice()');
                            input1.setAttribute('pid',product.id);
                            td1.appendChild(input1);

                            var td2 = document.createElement('td');
                            td2.setAttribute('class','t-data ring-in');
                            var a1 = document.createElement('a');
                            a1.style.width = '27%';
                            a1.setAttribute('href','product.html?id='+product.id+'&t='+token);
                            a1.setAttribute('class','at-in');
                            var img1 = document.createElement('img');
                            img1.style.width = '100%';
                            img1.setAttribute('src',product.cover);
                            img1.setAttribute('class','img-responsive');
                            a1.appendChild(img1);
                            var div1 = document.createElement('div');
                            div1.setAttribute('class','sed');
                            var h5 = document.createElement('h5');
                            h5.innerHTML = product.title;
                            div1.appendChild(h5);
                            td2.appendChild(a1);
                            td2.appendChild(div1);

                            var td3 = document.createElement('td');
                            td3.setAttribute('class','t-data money');
                            td3.innerHTML = '￥'+product.price;

                            var td4 = document.createElement('td');
                            td4.setAttribute('class','t-data');
                            var div2 = document.createElement('div');
                            div2.setAttribute('class','quantity');
                            var div3 = document.createElement('div');
                            div3.setAttribute('class','quantity-select');
                            var div4 = document.createElement('div');
                            div4.setAttribute('price',product.price);
                            div4.setAttribute('class','entry value-minus');
                            div4.setAttribute('onclick','minus(this)');
                            div4.innerHTML = '&nbsp;';
                            var div5 = document.createElement('div');
                            div5.setAttribute('class','entry value');
                            var span = document.createElement('span');
                            span.setAttribute('class','span-1');
                            span.innerHTML = 1;
                            div5.appendChild(span);
                            var div6 = document.createElement('div');
                            div6.setAttribute('price',product.price);
                            div6.setAttribute('class','entry value-plus active');
                            div6.setAttribute('onclick','plus(this)');
                            div6.innerHTML = '&nbsp;';
                            div3.appendChild(div4);
                            div3.appendChild(div5);
                            div3.appendChild(div6);
                            div2.appendChild(div3);
                            td4.appendChild(div2);

							var td5 = document.createElement('td');
							td5.setAttribute('class','t-data t-w3l');
							var a5 = document.createElement('a');
							a5.setAttribute('class','add-1');
							a5.setAttribute('onclick','deleteFromCart('+cartData[i].id+')');
							a5.innerHTML = 'DELETE';
							td5.appendChild(a5);


                            tr.appendChild(td1);
                            tr.appendChild(td2);
                            tr.appendChild(td3);
                            tr.appendChild(td4);
                            tr.appendChild(td5);

                            cartTable.appendChild(tr);
                        }
                    }
                }

                loadCart();
                function goumai() {
					var cartids = document.getElementsByName('selectone');
					var pids = '';
					var nums = '';
					for(i = 0; i < cartids.length; i ++){
					    if(cartids[i].checked){
					        pids += ','+cartids[i].getAttribute('pid');
                            var num = cartids[i].parentNode.parentNode.childNodes[3].childNodes[0].childNodes[0].childNodes[1].childNodes[0];
                            console.log('num',num);
                            nums += ','+num.innerText;
						}
					}
					pids = pids.substr(1,pids.length-1);
                    nums = nums.substr(1,nums.length-1);
					//window.location = 'order.html?t='+token+'&u='+uid+'&p='+pids+'&n='+nums;
                    window.location = 'order.html?t='+token+'&p='+pids+'&n='+nums;
                }
			</script>
	<!--quantity-->
			

<!--footer-->
<div class="footer">
	<div class="container">
		<div class="col-md-3 footer-grid">
			<h3>About Us</h3>
			<p>Big Store 是阿里巴巴集团全力打造的网上超市。Big Store 为广大网购消费者提供进口食品、食品饮料、粮油副食、美容洗护、家居用品、家庭清洁、
				母婴用品等所有生活必需品，商品品质100%保证。随时随地，轻松用手机或鼠标逛超市，生活快消品一次性购齐，不用排队、送货上门，
				还提供7天无理由退货服务。Big Store，让生活更简单。</p>
		</div>

		<div class="col-md-2 footer-grid "></div>

		<div class="col-md-3 footer-grid ">
			<h3>Menu</h3>
			<ul>
				<li><a href="index.html">主页</a></li>
				<li><a href="hot.html">热卖商品</a></li>
				<li><a href="activities.html">促销活动</a></li>
				<li><a href="contact.html">联系我们</a></li>
			</ul>
		</div>

		<div class="col-md-3 footer-grid">
			<h3>My Account</h3>
			<ul>
				<li><a href="login.html">登录</a></li>
				<li><a href="register.html">注册</a></li>
				<li><a href="wishlist.html">收藏</a></li>
				<li><a href="cart.html">购物车</a></li>
			</ul>
		</div>
		<div class="clearfix"></div>

		<div class="copy-right">
			<p> &copy; 2018 Big store. All Rights Reserved </p>
		</div>
	</div>
</div>
<!-- //footer-->
<!-- smooth scrolling -->
<script src="js/header_category.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
            var alist = document.getElementsByTagName('a');
            console.log('alist', alist);
            for (i = 0; i < alist.length; i++) {
                var hrefstr = alist[i].getAttribute('href');
                if(hrefstr == null){
                    continue;
                }
                console.log('hrefstr', hrefstr);
                if(hrefstr.indexOf('?')>0){
                    hrefstr = hrefstr +'&t='+token;
                }else{
                    hrefstr = hrefstr +'?t='+token;
                }
                alist[i].setAttribute('href', ''+hrefstr);
            }

            loadUserName(token);
		$().UItoTop({ easingType: 'easeOutQuart' });
		});
	</script>
	<a href="#" id="toTop" style="display: block;"> <span id="toTopHover" style="opacity: 1;"> </span></a>


</body>
</html>